package com.lllteam.exam.account.library.provider

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper

class DBOpenHelper(context: Context): SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) {
    companion object {
        // database values
        const val DB_VERSION = 2
        const val DB_NAME = "exam.db"

        // account table
        const val TABLE_NAME = "account"
        const val CREATE_SQL = "CREATE TABLE $TABLE_NAME" +
                "(" +
                "_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "name TEXT NOT NULL, " +
                "en_name TEXT NOT NULL, " +
                "grade TEXT NOT NULL, " +
                "mobile TEXT NOT NULL, " +
                "seq_id TEXT, " +
                "school TEXT, " +
                "address TEXT" +
                ")"
    }

    override fun onCreate(db: SQLiteDatabase?) {
        db?.execSQL(CREATE_SQL)
    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        db?.execSQL("DROP TABLE IF EXISTS $TABLE_NAME");
        onCreate(db)
    }
}